/*给定不同面额的硬币和一个总金额。写出函数来计算可以凑成总金额的硬币组合数。假设每一种面额的硬币有无限个。
*
* 输入: amount = 5, coins = [1, 2, 5]
* 输出: 4
* 解释: 有四种方式可以凑成总金额:
* 5=5
* 5=2+2+1
* 5=2+1+1+1
* 5=1+1+1+1+1

* */

package Leetcode;

public class leetcode518 {

    public static void main(String[] args) {

        leetcode518 obj = new leetcode518();
        int amount = 5;
        int[] coins = {1, 2, 5};
        System.out.println(obj.change(amount, coins));
    }

    public int change(int amount, int[] coins){

        int[] dp = new int[amount + 1];
        dp[0] = 1;
        for (int coin : coins){
            for (int i = coin;i <= amount;i++){
                dp[i] += dp[i - coin];
            }
        }
        return dp[amount];
    }
}
